package com.stars.home.widget

import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.databinding.DataBindingUtil
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.home.R
import com.stars.home.activity.WebViewActivity
import com.stars.home.databinding.WidgetPolicyBinding
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

open class WidgetPolicy constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : LinearLayout(context, attrs, defStyleAttr) {
    lateinit var binding: WidgetPolicyBinding

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

    private fun initView(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.widget_policy, this, true)
        orientation = HORIZONTAL
        gravity = Gravity.CENTER

    }

    private fun listeners() {
        binding.tvPrivatePolicy.onClick {
            UiSwitch.bundle(context, WebViewActivity::class.java, B.with().putString("url", "http://www.baidu.com").ok())
        }
        binding.tvUserPolicy.onClick {
            UiSwitch.bundle(context, WebViewActivity::class.java, B.with().putString("url", "http://www.baidu.com").ok())
        }

    }

    init {
        initView(context, attrs, defStyleAttr)
        listeners()
    }
}
